package com.syq.controller;

import com.syq.feign.SearchFeign;
import com.syq.pojo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName: CustomerController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/16 11:14
 */

@RestController
@RequestMapping("/customer")
public class CustomerController {
//    //负载均衡 loadBalance
//    @Autowired
//    private LoadBalancerClient loadBalancerClient;//只能和注册中心进行注册与发现

    @Autowired
    private SearchFeign searchFeign;

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/list")
    public String list() {
//        ServiceInstance instance = loadBalancerClient.choose("EUREKA-SEARCH");
//        //uri :http://localhost:9002
//        //url :http://localhost:9002/search/list
//        String uri = instance.getUri().toString();
//        //完整路径
//        String url=uri+"/search/list";
//        String searchContent = restTemplate.getForObject(url, String.class);
        String name = "syq";
        String searchContent = searchFeign.list(name);

        return "我是客户微服务，远程调用搜索服务:" + searchContent;
    }

    @PostMapping("/pojo")
    public String pojo(@RequestBody Customer customer) {
        String searchContent = searchFeign.pojo(customer);

        return "我是客户微服务，远程调用搜索服务:" + searchContent;
    }
}